package algorithm.unionfind;

/**
 * @Description:
 * @Author Ammar
 * @Create 2023/5/18 07:47
 */
public class QuickUnion_rank_compression extends QuickUnion_rank{
    public QuickUnion_rank_compression(int capacity) {
        super(capacity);
    }

    @Override
    public int find(int v) {
        rangeCheck(v);
        if (v != parents[v]) {
            // 将路径上的所有节点都直接连接到根节点上
            parents[v] = find(parents[v]);
        }
        return parents[v];
    }
}
